﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace PruebaAutoResetEvent
{
    class Program
    {
        static AutoResetEvent resetEvent = new AutoResetEvent(false);
        //static ManualResetEvent resetEvent = new ManualResetEvent(false);

        static void Main(string [] args)
        {
            f();
        }

        static void f()
        {
            for (int i = 0; ; i++)
            {
                g();

                if ((i % 1000 == 0) && (i != 0))
                    Console.WriteLine(i);

                resetEvent.WaitOne();
                //resetEvent.Reset();
            }
        }

        static void g()
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(
                (object o) =>
                {
                    resetEvent.Set();
                }));
        }
    }
}
